/*
 * ZBrowser is an embeddable browser component.
 * Copyright (C) Author: Gangadhar Nagesh Metla (Novell, Inc.)
 * nmetla74@gmail.com 
 * Version 1.0
 * 1/3/2009
 * Filename PropPageCmdDialogLauncher.java
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

package com.novell.zenworks.agent.zbrowser.cmddialogs;

import com.novell.zenworks.agent.zbrowser.NavigationUtils;

public class PropPageCmdDialogLauncher implements Runnable//extends AsyncExec
{
    private InvokePropPageCmdDlg propPageCmd;

    public PropPageCmdDialogLauncher(InvokePropPageCmdDlg propPageCmd)
    {
        super();
        this.propPageCmd = propPageCmd;
    }

    public void run()
    {
        try
        {
            Object retVal = work();
            finish(retVal);
        } catch (Exception e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public Object work() throws Exception
    {
        return NavigationUtils.getServer().invokePropPageCommand(propPageCmd.getPageId(), propPageCmd.getCmdData());
        
    }
    
    public void finish(Object retVal)
    {
        if(propPageCmd.busyDlg != null)
        {
            if(retVal == null)
            {
                propPageCmd.busyDlg.updateCaption(propPageCmd.getSuccessCaption(), PropPageCmdDialog.SUCCESS);
                propPageCmd.busyDlg.showButton();
            }
            else
            {
                propPageCmd.busyDlg.updateCaption(propPageCmd.getErrorCaption(), PropPageCmdDialog.ERROR);
                propPageCmd.busyDlg.showErrorDetailMessage(retVal.toString());
            }            
        }
    }

}
